﻿using System;
using System.Xml;
using System.Collections.Specialized;
using System.Reflection;
using System.Configuration;


namespace AutoResumeSend.Entity
{
    public  class Config
    {
        /// <summary>
        /// sql连接字符串
        /// </summary>
        public static string SqlConnectionString
        {
            get { return GetConfig("SqlConnectionString", @""); }
        }

        /// <summary>
        /// 求职信路径
        /// </summary>
        public static string EmailBodyPath
        {
            get
            {
                return GetConfig("EmailBodyPath", @"G:\doc\resume.txt");
            }
        }

        /// <summary>
        /// 屏蔽的邮件
        /// </summary>
        public static string ForbidEmail
        {
            get
            {
                return GetConfig("ForbidEmail", @"sjqtemp@163.com");
            }
        }

        /// <summary>
        /// 邮件
        /// </summary>
        public static string Mail
        {
            get
            {
               return GetConfig("Mail", @"kucao@126.com");
            }
        }

        /// <summary>
        /// 邮件服务器地址
        /// </summary>
        public static string EmailServrceUrl
        {
            get
            {
                return GetConfig("EmailServrceUrl", @"smtp.126.com");
            }
        }

        /// <summary>
        /// 抓取最多的页数
        /// </summary>
        public static int PageCount
        {
            get
            {
                int count = 6;
                if (!int.TryParse(GetConfig("PageCount", @"6"), out count))
                    count = 6;
                return count;
            }
        }

        /// <summary>
        /// 邮件服务端口
        /// </summary>
        public static int EmailPort
        {
            get
            {
                int port=25;
                if (!int.TryParse(GetConfig("EmailPort", @"25"), out port))
                    port = 25;
                return port;

            }
        }

        /// <summary>
        /// 邮件登录名
        /// </summary>
        public static string LoginName
        {
            get
            {
                return GetConfig("LoginName", @"kucao");
            }
        }

        /// <summary>
        /// 邮件密码
        /// </summary>
        public static string Password
        {
            get
            {
               return GetConfig("Password", @"19841002");
            }
        }

        /// <summary>
        /// 附件地址
        /// </summary>
        public static string AttchmentsPath
        {
            get
            {
                return GetConfig("AttchmentsPath", @"G:\doc\resume.doc");
            }
        }

        /// <summary>
        /// 抓取时间到最近抓取的时间间隔 默认1天
        /// </summary>
        public static int IntervalDay
        {
            get
            {
                int day=1;
                if(!int.TryParse(GetConfig("IntervalDay", @"1"),out day))
                    day=1;
                return day;
            }
        }

        

        /// <summary>
        /// 发送邮件的主题前缀
        /// </summary>
        public static string SubjectTitle
        {
            get
            {
                return GetConfig("SubjectTitle", @"涂云横应聘");
            }
        }

        /// <summary>
        /// 日志文件
        /// </summary>
        public static string LogFileName
        {
            get
            {
                return GetConfig("LogFileName", @"D:\logInfo.txt");
            }
        }

        /// <summary>
        /// 职位的最大工作年限
        /// </summary>
        public static int MaxJobYear
        {
            get
            {
                int maxJobYear = 0;
                if (!int.TryParse(GetConfig("MaxJobYear", @"3"), out maxJobYear))
                    maxJobYear = 3;
                return maxJobYear;
            }
        }

        /// <summary>
        /// 工作地区
        /// </summary>
        public static string JobArea
        {
            get
            {
                return GetConfig("JobArea", @"上海");
            }
        }

        /// <summary>
        /// 职位标题包含的关键字列表
        /// </summary>
        public static string JobTitle
        {
            get
            {
                return GetConfig("JobTitle", @"c#,asp.net");
            }
        }

        /// <summary>
        /// 职位描述中包含的关键字
        /// </summary>
        public static string JobContent
        {
            get
            {
                return GetConfig("JobContent", @"xml,ajax,oracle");
            }
        }


        #region tools
        private static NameValueCollection _settings = null;

        public static NameValueCollection Settings
        {
            get { return Config._settings; }
            set { Config._settings = value; }
        }



        private static string GetConfig(string key, string defaultValue)
        {

            if (_settings == null)
                _settings = ConfigurationManager.AppSettings;

            if (Settings[key] != null)
                return Settings[key];
            else
                return defaultValue;

        }
        #endregion
    }
}
